package com.woniu34.order.controller;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.woniu.common.core.domain.AjaxResult;
import com.woniu34.order.domain.Order;
import com.woniu34.order.domain.request.OrderRequest;
import com.woniu34.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("order")
public class OrderController {


    @Autowired
    private OrderService orderService;


    @GetMapping("query/orderId")
    public String queryOrderSn(){
        //参数1为终端ID
        //参数2为数据中心ID
//        Snowflake snowflake = IdUtil.getSnowflake(1, 1);
//        long id = snowflake.nextId();
//        System.out.println("orderId="+System.currentTimeMillis());
        return ""+System.currentTimeMillis();
    }

    @PostMapping("makeOrder")
    public AjaxResult makeOrder(@RequestBody OrderRequest request){

        System.out.println(request);
        orderService.makeOrder(request);

        return AjaxResult.success();
    }

    @RequestMapping("queryById")
    public Order queryById(@RequestParam("orderId") Long orderId){

        return orderService.queryById(orderId);
    }
}
